package com.bohua.Car.admin.service.Impl;

import com.bohua.Car.admin.common.Lay;
import com.bohua.Car.admin.common.Msg;
import com.bohua.Car.admin.common.Pie;
import com.bohua.Car.admin.dao.ChecktablegMapper;
import com.bohua.Car.admin.entity.Checktableg;
import com.bohua.Car.admin.entity.Customers;
import com.bohua.Car.admin.service.ChenckService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ChenckServiceImpl implements ChenckService {

    @Resource
    private ChecktablegMapper checktablegMapper;

    @Override
    public Msg addChenck(Checktableg checktableg) {
        int i=checktablegMapper.insert(checktableg);
        Msg msg=new Msg();
        if(i>0){
            msg.setMsg("添加成功");
        }else {
            msg.setCode(-1);
            msg.setMsg("添加失败");
        }
        return msg;
    }

    @Override
    public Msg updeteChenck(Checktableg checktableg) {
        int i=checktablegMapper.updateByPrimaryKey(checktableg);
        Msg msg=new Msg();
        if(i>0){
            msg.setMsg("修改成功");
        }else {
            msg.setCode(-1);
            msg.setMsg("修改失败");
        }
        return msg;
    }

    @Override
    public Msg delChenck(Checktableg checktableg) {
        int i= checktablegMapper.deleteByPrimaryKey(checktableg.getCheckid());
        Msg msg=new Msg();
        if (i>0){
            msg.setMsg("删除成功");
        }else {
            msg.setCode(-1);
            msg.setMsg("删除失败");
        }
        return msg;
    }

    @Override
    public Lay getAll(Checktableg checktableg, Integer page, Integer limit) {
        //进行分页
        PageHelper.startPage(page,limit);
        List<Checktableg> car=checktablegMapper.getAll(checktableg);
        PageInfo info=new PageInfo(car);
        Lay lay = new Lay();
        lay.setPage(page);
        lay.setCount(info.getTotal());
        lay.setData(info.getList());
        lay.setLimit(limit);
        return lay;
    }

    @Override
    public List<Pie> ChenckBar() {
        return checktablegMapper.Bar();
    }

}
